<?php
namespace App\Services;

use App\Models\Config;
use App\Models\TimeConfig;

class ConfigService {
    const APPOINT_RANGE_TIME = 'APPOINT_RANGE_TIME';
    const APPOINT_MAX_NUM = 'APPOINT_MAX_NUM';
    const CACHE_KEY = 'config_time';
    const CACHE_CONFIG_KEY = 'config_cache';

    public static function getAll() {
        return \Cache::remember(self::CACHE_KEY, 3600*24*10, function () {
            return TimeConfig::all();
        });
    }

    public static function getValue($key) {
        $map = \Cache::remember(self::CACHE_CONFIG_KEY, 3600*24*10, function () {
            return Config::all()->pluck('value', 'key');
        });
        return $map[$key] ?? '';
    }

    public static function forget() {
        \Cache::forget(self::CACHE_KEY);
        \Cache::forget(self::CACHE_CONFIG_KEY);
    }


}